package com.project.advertisement.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;

import android.net.ConnectivityManager;
import android.net.NetworkInfo;

import com.project.R;



public class Utility {
	
	public static boolean validateTextBox(String value){
		if(value==null || value.equals(""))
			return false;
		return true;
		
	}
	public static boolean validateEmail(String emailId){
		String emailPattern="^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@"
				+ "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
		Pattern pattern=Pattern.compile(emailPattern);
		Matcher matcher=pattern.matcher(emailId);		
		return matcher.matches();
	}
	
	public static boolean validateCharOnly(String childName){		
		String charOnly="[a-zA-Z ]+";
		Pattern pattern=Pattern.compile(charOnly);
		Matcher matcher=pattern.matcher(childName);
		return matcher.matches();
	}
	public static boolean validateNumberOnly(String uniqueNumber){		
		String charOnly="[0-9]+";
		Pattern pattern=Pattern.compile(charOnly);
		Matcher matcher=pattern.matcher(uniqueNumber);
		return matcher.matches();
	}
	
	public static boolean isConnectingToInternet(Context _context){
        ConnectivityManager connectivity = (ConnectivityManager) _context.getSystemService(Context.CONNECTIVITY_SERVICE);
          if (connectivity != null) 
          {
              NetworkInfo[] info = connectivity.getAllNetworkInfo();
              if (info != null) 
                  for (int i = 0; i < info.length; i++) 
                      if (info[i].getState() == NetworkInfo.State.CONNECTED)
                      {
                          return true;
                      }
 
          }
          return false;
    }
	public static void showErrorMessage(String message,Context _context) {
		AlertDialog alertDialog = new AlertDialog.Builder(
				_context).create();
		alertDialog.setTitle("ERROR !");
		alertDialog.setMessage(message);
		alertDialog.setIcon(R.drawable.error);
		alertDialog.setButton("OK", new DialogInterface.OnClickListener() {

			public void onClick(DialogInterface dialog, int which) {
				return;

			}
		});
		alertDialog.show();
	}
	
	public static String sendMail(String emailTo,String subject,String messageBody,Context _context) {
		Intent emailIntent=new Intent(android.content.Intent.ACTION_SEND);
		 emailIntent.setType("text/html");
         emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{ emailTo});
         emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
         emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, messageBody);
        _context.startActivity(Intent.createChooser(emailIntent, "Send mail..."));
		return "success";
	}
	
	
	
}
